******************************************************************************
* Stata replication do-file for the manuscript:	                             *
* "WHO GETS INTO GOVERNMENT? COALITION FORMATION IN EUROPEAN DEMOCRACIES"    *
******************************************************************************


/* Please note that the user-written Stata program 'miest' is required. This program can be found at Ken Scheve's homepage: http://pantheon.yale.edu/~ks298/miv2.zip.
   In addition, the presentation of the results below requries the user-written Stata programs estwrite, estread and estout. To install these programs type 
   "ssc install estwrite" and "ssc install estout" in Stata. Before you start, make sure that you have all data files in your Stata working directory! */


set more off
set matsize 400

version 12.1  /* Please note that the code below is writen so that earlier versions of Stata (i.e. 9.2, 10 and 11) should work as well (only Stata 11 tested) */ 


***************
*   TABLE 2   *
***************

/* To display the individual output for each model, please delete the first word "qui" (quietly). After doing so - to suppress the intermediate output 
of the 5 analyses for 5 imputed datasets delete the option "iout" after the comma for each model */

* Model 1
qui miest sim logit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty  ///
govexperience   effectivenrlegislativeparties volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 ///
C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26  ///
 _spline1 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7, cluster(uniqueidparty) iout

estwrite using T2, append 
 
* Model 2
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty   ///
govexperience   effectivenrlegislativeparties volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 ///
C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7, re iout
 
estwrite using T2, append 
 
* Model 3
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty   ///
govexperience   effectivenrlegislativeparties volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 ///
C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & singlepartymajority==0 & easteufirstelection==0, re iout

estwrite using T2, append 

* Model 4
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty   ///
govexperience   effectivenrlegislativeparties volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 ///
C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & singlepartymajority==0 & easteufirstelection==0 & year>1989, re iout
 
estwrite using T2, append
estread using T2 
estout  _estread_1 _estread_2 _estread_3 _estread_4, cells(b(star fmt(4)) se(par fmt(4))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
style(fixed) stats(sigma_u ll rho chi2 N) keep(seatsshareparl seatssharechangeperc largestparty  ///
median_distance_CMP  incumbentcabparty govexperience   effectivenrlegislativeparties volatility _cons) title(TABLE 2) 

erase T2.sters
estimates clear

***************
*    TABLE 3  *
***************

/* To display the individual output for each model, please delete the first word "qui" (quietly). After doing so - to suppress the intermediate output 
of the 5 analyses for 5 imputed datasets delete the option "iout" after the comma for each model */

* Model 5
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty   govexperience   effectivenrlegislativeparties /// 
volatility C1 C2 C7 C8 C9 C10  C12 C13 C14 C17 C18 C19 C21 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
D7 if west==1 & year>1989, re iout
 
estwrite using T3, append
 
* Model 6
 
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty govexperience csp  effectivenrlegislativeparties ///
volatility C4 C6 C11 C15 C16 C20 C22 C23 C24 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
D7 if west!=1 , re iout

estwrite using T3, append
 
* Model 7
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty  govexperience   effectivenrlegislativeparties ///
 volatility C1 C2 C7 C8 C9 C10  C12 C13 C14 C17 C18 C19 C21 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4  _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
D7 if filter_ct!=1 & west==1 & singlepartymajority==0 & year>1989, re iout

estwrite using T3, append
 
*Model 8
 
qui miest sim xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 median_distance_CMP  incumbentcabparty  govexperience csp  effectivenrlegislativeparties ///
 volatility C4 C6 C11 C15 C16 C20 C22 C23 C24 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D7 if filter_ct!=1 & west!=1 & singlepartymajority==0 &  easteufirstelection==0, re iout
 
estwrite using T3, append
estread using T3
estout _estread_1 _estread_2 _estread_3 _estread_4, cells(b(star fmt(4)) se(par fmt(4))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(sigma_u ll rho chi2 N) ///
varlabels(_cons Constant) keep(seatsshareparl seatssharechangeperc largestparty  ///
median_distance_CMP  incumbentcabparty govexperience csp  effectivenrlegislativeparties volatility _cons) title(TABLE 3)
erase T3.sters
estimates clear



*************************
*  APPENDIX - TABLE A2  *
*************************

/* Before executing the command lines below, please load the appenidx data file */

use appendix_dataset.dta, clear

* Model A1

qui logit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
  leftrightmediandistance  incumbentcabparty  govexperience   effectivenrlegislativeparties ///
volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7, cluster(uniqueidparty)

 est store A1

* Model A2
qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty govexperience   effectivenrlegislativeparties  ///
 volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7, re

 est store A2
 
*Model A3
qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty govexperience   effectivenrlegislativeparties ///
 volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & singlepartymajority==0 & easteufirstelection==0, re 

 est store A3

*Model A4
qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty  govexperience   effectivenrlegislativeparties  ///
 volatility C1 C2 C3 C4 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & singlepartymajority==0 & easteufirstelection==0 & year>1989, re 

 est store A4
 
* Model A5
qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty   govexperience   effectivenrlegislativeparties ///
 volatility  C1 C2 C7 C8 C9 C10  C12 C13 C14 C17 C18 C19 C21 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if west==1 & year>1989, re

 est store A5
 
 * Model A6

qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty  govexperience   effectivenrlegislativeparties  ///
 csp volatility C4 C6 C11 C15 C16 C20 C22 C23 C24 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if west!=1 , re 

 est store A6
 
* Model A7

qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
leftrightmediandistance  incumbentcabparty  govexperience   effectivenrlegislativeparties ///
volatility  C1 C2 C7 C8 C9 C10  C12 C13 C14 C17 C18 C19 C21 C25 C26  ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & west==1 & singlepartymajority==0 & year>1989, re 

 est store A7

* Model A8

qui xtlogit cabparty  seatsshareparl seatssharechangeperc largestparty  ///
 leftrightmediandistance  incumbentcabparty  govexperience   effectivenrlegislativeparties  ///
 csp volatility  C4 C6 C11 C15 C16 C20 C22 C23 C24 ///
 _spline1 _spline2 _spline3 _spline4 _spline5 _spline6 _spline7 _spline8 _spline9 _spline10 ///
 D2 D3 D4 D5 D6 D7 if filter_ct!=1 & west!=1 & singlepartymajority==0 &  easteufirstelection==0, re

est store A8

estout A1 A2 A3 A4 A5 A6 A7 A8, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(sigma_u ll rho chi2 N) ///
varlabels(_cons Constant) keep(seatsshareparl seatssharechangeperc largestparty  ///
leftrightmediandistance  incumbentcabparty govexperience csp  effectivenrlegislativeparties volatility _cons) title(TABLE A2)
est clear
